//index.js
//获取应用实例
var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url:app.setting.att_url,
		loading:true,
		page:0,
		main:{'syscolor':'var(--syscolor)'},
		action:'{action}',
		pagetitle:app.setting.title,
	},
	onReady: function (){
	},
	onPullDownRefresh: function (){
		var the=this;
		var opt={};
		the.onLoad(opt);
		setTimeout(function(){
			wx.stopPullDownRefresh()
		},1000);
	},
	onLoad: function (opt){
		var the=this;
		wx.setNavigationBarTitle({'title':the.data.pagetitle});
		var route=the.route;
		var ShowGoshare=false;
		if(opt && opt.isgoshare){
			ShowGoshare=true
		}
		the.setData({
			route:route,
			ShowGoshare:ShowGoshare
		});
		if(route){
			var path=route.slice(0,-6).split('/');
			app.access.plugin=path.shift();
			app.access.action=path.join('.');
		}
		if(opt){
			opt=app.util.upopt(opt);
			app.access.query =app.util.made_query(opt,true);
			app.access.op=opt.op?opt.op:'';
		}
		the.getpagedata();
	},
	getpagedata: function (){
		var the=this;
		app.util.get(app.access,function(res){
			//console.log('{action}');console.log(res);
			the.setData({
				pagedata:res,
				pluginnav:app.session.menus,
				ShowAuthM:res.show_setmember==2?true:false,
				action:app.access.plugin+'/'+app.access.action+'/',
			});
		});
	},
	goback: function() {
		var pages=getCurrentPages()
		if(pages.length>1){
			wx.navigateBack({
				'delta':1,
				'fail':function(){
					app.util['access'](app.plugin_name+'/index/');
				},
			})
		}else{
			app.util['access'](app.plugin_name+'/index/');
		}
    },
	info_login:function(e){
		//根据openid为用户登陆，此处尝试获取用户信息
		var the=this;
		app.util.getUserInfo(e,function(res){
			if(res && res.userInfo){
				app.isgetUserInfo=true
				the.setData({
					ShowAuthM:false
				})
				the.onLoad();
			}else{
				return false;
			}
		});
	},
	closeAuthM:function(){
		var the=this;
		the.setData({
			ShowAuthM:false
		})
	},
  	click:function(e){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=e.currentTarget.dataset;
		app.util[data.func](data.params);
	},
	formSubmit:function(e){
		var data=e.detail.value;
		app.util.post('post',data);
	},
	onShareAppMessage: function (res) {
		var the = this
		var pagedata = the.data.pagedata
		if (res.from === 'button') {
		}
		var path=the.data.route+'?'+app.access.query;
		if(app.access.op){
			path +='&op='+app.access.op;
		}
		if(pagedata.fromuser){
			path +='&fromuser='+pagedata.fromuser;
		}
		return {
		  title: the.data.pagetitle,
		  path: path,
		  desc: app.setting.sharedesc,
		  success: function(res) {
		  },
		  fail: function(res) {
		  }
		}
	}
});